#include <iostream>
using namespace std;

signed main()
{
	string s1,s2,s3,s4;
	cin>>s1>>s2>>s3>>s4;
	int flag=1;
	int j;
//	for(j=0;j<s1.size()&&j<s2.size();j++){
//		if((s1[i]>='a'&&s1[i]<='z')||(s1[i]>='A'&&s1[i]<='Z'))break;
//	}
	for(int i=j;i<s1.size()&&i<s2.size();i++){
		if(s1[i]==s2[i]){
			if(flag==1&&s1[i]>='A'&&s1[i]<='G'){
				switch(s1[i]){
					case 'A':cout<<"MON ";break;
					case 'B':cout<<"TUE ";break;
					case 'C':cout<<"WED ";break;
					case 'D':cout<<"THU ";break;
					case 'E':cout<<"FRI ";break;
					case 'F':cout<<"SAT ";break;
					case 'G':cout<<"SUN ";break;
				}
				flag++;
			}
			else if(flag==2){
				if(s1[i]>='0'&&s1[i]<='9'){
					cout<<"0"<<(s1[i]-'0');
					goto minute;
				}
				else if(s1[i]>='A'&&s1[i]<='N'){
					cout<<(s1[i]-'A')+10;
					goto minute;
				}
			}
		}
	}
	minute:
	for(int i=0;i<s3.size()&&i<s4.size();i++){
		if(s3[i]==s4[i]&&(s3[i]>='A'&&s3[i]<='Z'||s3[i]>='a'&&s3[i]<='z')){
			cout<<":";
			if(i<10)cout<<"0"<<i;
			else cout<<i;
			return 0;
		}
	}
	return 0;
 } 
